package com.naiterui.ehp.bp.security.jwt;

import com.naiterui.ehp.bp.security.properties.SecurityProperties;
import com.naiterui.ehp.bp.security.service.IOnlineUserService;
import com.naiterui.ehp.bp.security.service.UserCacheClean;
import lombok.RequiredArgsConstructor;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@RequiredArgsConstructor
public class TokenConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

  private final TokenProvider tokenProvider;
  private final SecurityProperties securityProperties;
  private final IOnlineUserService onlineUserService;
  private final UserCacheClean userCacheClean;

  @Override
  public void configure(HttpSecurity http) {
    TokenFilter customFilter = new TokenFilter(this.tokenProvider, this.userCacheClean, this.securityProperties, this.onlineUserService);
    http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
  }

}
